import numpy as np

sentence = 'hihello'
x_char = sentence[:-1]
y_char = sentence[1:]

char_set = list(set(x_char)|set(y_char))
idx2char = char_set

char2idx = {c: i for i, c in enumerate(char_set)}

x_data = np.array([
    [char2idx[c] for c in x_char],
    [char2idx[c] for c in x_char],
    [char2idx[c] for c in x_char]
], dtype=np.int32)
y_data = [
    [char2idx[c] for c in y_char],
    [char2idx[c] for c in y_char],
    [char2idx[c] for c in y_char]
]

nb_input = len(char_set)
nb_output = len(char_set)
nb_neuron = 15
layers_num = 2
dict_len = len(char_set)
nb_steps = len(x_data[0])

x_data_oh = np.eye(dict_len, dtype=np.int32)[x_data]


def h_to_str(h):
    h_idx = np.argmax(h, axis=1)
    h_idx = h_idx.reshape(-1, nb_steps)
    str = [''.join([idx2char[idx] for idx in idx_row]) for idx_row in h_idx]
    return str
